<?php
/**
 * Created by PhpStorm.
 * User: tianleilei
 * Date: 2017/8/8
 * Time: 13:56
 */

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    //表名
    protected $table = 'project_user';
    //表主键
    protected $primaryKey = "user_id";

    /**
     *
     * 用户和项目的关系
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function project()
    {
        return $this->belongsTo('App\Model\Project', 'user_project_code', 'project_code');
    }

    public function scopeUserGh($query, $value)
    {
        return $query->where('user_gh', $value);
    }

    public function scopeProject($query, $value)
    {
        if (!empty(session('project_code'))) {

            $value = session('project_code');
        }
        return $query->where('user_project_code', $value);
    }

    public function getUserInfo($user_gh, $user_project_code)
    {
        return $this->userGh($user_gh)->project($user_project_code)->first();

    }

}
